package com.study.thread.fakeShare;


import sun.misc.Contended;

public class FakeShare {

    private static volatile int a = 0;

    @Contended
    private static int b = 1;

    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            set();
        });

        Thread t2=new Thread(()->{
            long beginTime=System.currentTimeMillis();
            get();
            long endTime=System.currentTimeMillis();
            System.out.println("耗时"+(endTime-beginTime));
        });
        t1.start();
        t2.start();
        t2.join();
    }
    public static void get(){
        for (int i = 0; i <3000000 ; i++) {
            System.out.println(b);
        }
    }
    public static void set(){
        for (int i = 0; i <3000000 ; i++) {
            a=i;
        }
    }
}

